package com.lili.controller.officer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lili.base.constants.ResponseConstant;
import com.lili.base.vo.ResultAPI;
import com.lili.service.ExamRecordService;
import com.lili.vo.request.officer.ToMarkExamReqVO;
import com.lili.vo.response.troop.ExamViewVO;
import com.lili.vo.response.officer.ToMarExamRecordRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Slf4j
@PreAuthorize("hasAnyRole('officer')")
@RequestMapping("/officer/record/")
@RestController("officerExamRecordController")
@Api(value = "军官对考卷进行管理", tags = "考卷管理API")
public class ExamRecordController {

    private final ExamRecordService examRecordService;


    @Autowired
    public ExamRecordController(ExamRecordService examRecordService) {
        this.examRecordService = examRecordService;
    }


    /**
     * 查看待批改的试卷列表
     * @param vo
     * @return
     */
    @PostMapping("list")
    @ApiOperation("查看待批改的试卷列表")
    public ResultAPI<IPage<ToMarExamRecordRespVO>> pageList(@RequestBody ToMarkExamReqVO vo){
        IPage<ToMarExamRecordRespVO> pages = examRecordService.selectToMarkPageList(vo);
        return new ResultAPI<>(ResponseConstant.SUCCESS,"",pages);
    }

    /**
     * 得到待批改的试卷
     * @param id
     * @return
     */
    @GetMapping("selectRecord/{id}")
    @ApiOperation("根据考卷编号得到待批改的试卷")
    public ResultAPI<ExamViewVO> selectRecord(@PathVariable Integer id){
        ExamViewVO viewVO = examRecordService.selectRecordById(id);
        return new ResultAPI<>(ResponseConstant.SUCCESS,"",viewVO);
    }

    @PostMapping("correct")
    @ApiOperation("批改试卷")
    public ResultAPI<String> correct(@RequestBody ExamViewVO vo){
        examRecordService.correct(vo);
        return new ResultAPI<>(ResponseConstant.SUCCESS,"批改完成","");
    }

}
